<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:in="http://java.sun.com/jsf/composite/inward"
                xmlns:pa="http://java.sun.com/jsf/composite/paymentMethod"
                xmlns:bill="http://java.sun.com/jsf/composite/inward/bill">
    <ui:define name="content">

        <h:panelGroup >
            <h:form  >
                <p:panel rendered="#{!inwardRefundController.printPreview}">
                    <f:facet name="header">
                        <p:outputLabel value="Inward Refund Payment"/>

                    </f:facet>
                    <p:panel header="BHT">
                        <p:autoComplete widgetVar="aPt2"  id="acPt2" forceSelection="true" converter="admis"
                                        value="#{inwardRefundController.current.patientEncounter}" 
                                        completeMethod="#{admissionController.completePatientPaymentMax}"
                                        var="apt2" itemLabel="#{apt2.bhtNo}" 
                                        itemValue="#{apt2}" size="30"  style="width: 400px;">
                            <p:ajax event="itemSelect" process="acPt2" update="panSearch2 paid" 
                                    listener="#{inwardRefundController.calculteFinalBillMax}"/>
                            <p:column>
                                #{apt2.bhtNo}
                            </p:column>
                            <p:column>
                                #{apt2.patient.person.nameWithTitle}
                            </p:column>
                            <p:column>
                                <h:outputLabel value="#{apt2.currentPatientRoom.roomFacilityCharge.name}"/>
                            </p:column>
                        </p:autoComplete>   


                        <h:panelGroup id="panSearch2">
                            <in:bhtDetail admission="#{inwardRefundController.current.patientEncounter}"/>
                        </h:panelGroup>
                    </p:panel>
                    <p:panel header="Paid Amount" id="paid">
                        <p:panelGrid columns="2">
                            <h:outputLabel value="Total Payments"/>
                            <h:outputLabel value="#{inwardRefundController.paidAmount}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </p:panelGrid>
                    </p:panel>
                    <p:panel header="Payment Detail">
                        <h:panelGrid columns="7">                        
                            <p:selectOneMenu   id="cmbPs" value="#{inwardRefundController.current.paymentMethod}"  >
                                <f:selectItem itemLabel="Select Payment Method" />
                                <f:selectItems value="#{inwardRefundController.paymentMethods}"  />
                                <p:ajax process="cmbPs" update="creditCard cheque slip  " event="change" />
                            </p:selectOneMenu>
                            <h:panelGroup id="creditCard" style="display: #{inwardRefundController.current.paymentMethod ne 'Card' ? 'none' : 'block'} ; ">
                                <pa:creditCard paymentMethodData="#{inwardRefundController.paymentMethodData}"/>
                            </h:panelGroup>

                            <h:panelGroup id="cheque" style="display: #{inwardRefundController.current.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; " >
                                <pa:cheque paymentMethodData="#{inwardRefundController.paymentMethodData}"/>
                            </h:panelGroup>

                            <h:panelGroup id="slip" style="display: #{inwardRefundController.current.paymentMethod ne 'Slip' ? 'none' : 'block'} ;">
                                <pa:slip paymentMethodData="#{inwardRefundController.paymentMethodData}"/>
                            </h:panelGroup>

                        </h:panelGrid>

                        <h:panelGrid columns="2">
                            <p:outputLabel value="Amount"/>
                            <p:inputText autocomplete="off" value="#{inwardRefundController.current.total}">
                                 <f:convertNumber pattern="#,##0.00" />
                            </p:inputText>
                            <p:commandButton id="btnRefund" ajax="false" value="Refund" 
                                            action="#{inwardRefundController.pay}"/>
                            <p:commandButton ajax="false" value="Clear" action="#{inwardRefundController.makeNull}"/>
                            <p:defaultCommand target="btnRefund"/>
                        </h:panelGrid>
                    </p:panel>

                </p:panel>
                <p:panel rendered="#{inwardRefundController.printPreview}">
                    <p:commandButton ajax="false" value="New Bill" action="#{inwardRefundController.makeNull}"/>
                    <bill:paymentRefund bill="#{inwardRefundController.current}"/>
                </p:panel>
            </h:form>

        </h:panelGroup>

    </ui:define>

</ui:composition>
